package com.zcxy.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.zcxy.anotation.Log;
import com.zcxy.core.bean.PageQuery;
import com.zcxy.core.bean.Response;
import com.zcxy.mybatis.bean.CommonStringParam;
import com.zcxy.mybatis.bean.SysUser;
import com.zcxy.sys.pojo.SysUserVo;
import com.zcxy.sys.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author zcc
 * @version 1.0.0
 * @ClassName SysUserController.java
 * @Description 用户
 * @createTime 2020-06-01
 */
@RestController
@RequestMapping("/api/sysUser")
@Api(tags = "<font  color='red'>用户管理</font>")
@Slf4j
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SysUserController {
    @Autowired
    private ISysUserService iSysUserService;

    @Log("获取用户数据列表")
    @PostMapping(value = "/queryPageList")
    @ApiOperation(value = "获取(用户)分页数据列表", notes = "获取(用户)分页数据列表")
    public Response<IPage<SysUserVo>> queryPageList(@RequestBody PageQuery<CommonStringParam> queryVo) {
        return Response.ok(iSysUserService.queryPageList(queryVo));
    }

    @Log("获取用户数据列表")
    @GetMapping(value = "/queryList")
    @ApiOperation(value = "获取数据列表", notes = "获取数据列表")
    public Response<List<SysUserVo>> queryList() {
        return Response.ok(iSysUserService.queryList());
    }


    @Log("添加用户数据")
    @PostMapping(value = "/add")
    @ApiOperation(value = "添加用户数据列", notes = "添加用户数据")
    public Response addSysUser(@RequestBody @Validated SysUser queryVo) {
        iSysUserService.addSysUser(queryVo);
        return Response.ok();
    }

    @Log("另存添加用户数据")
    @PostMapping(value = "/copyadd")
    @ApiOperation(value = "另存添加用户数据", notes = "另存添加用户数据")
    public Response copyadd(@RequestBody @Validated SysUser queryVo) {
        queryVo.setId("");
        iSysUserService.addSysUser(queryVo);
        return Response.ok();
    }


    @Log("修改用户数据")
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改用户数据", notes = "修改用户数据")
    public Response updateSysUser(@RequestBody @Validated SysUserVo queryVo) {
        iSysUserService.updateSysUser(queryVo);
        return Response.ok();
    }


    @Log(value = "批量删除用户")
    @ApiOperation("批量删除用户")
    @DeleteMapping("/dels")
    public Response<List<String>> deleteByIds(@RequestBody List<String> ids) {

        return Response.ok(iSysUserService.removeAllSysUser(ids));
    }

    @Log(value = "批量删除用户")
    @ApiOperation("批量删除用户")
    @DeleteMapping("/dels-t")
    public Response dels(@RequestBody List<String> ids) {
        iSysUserService.removeAllSysUser(ids);
        return Response.ok();
    }

    @Log("批量启用用户数据")
    @PutMapping(value = "/updateEnableT")
    @ApiOperation(value = "批量启用用户数据", notes = "批量启用用户数据")
    public Response updateEnableY(@RequestBody List<String> ids) {
        iSysUserService.updateEnable(ids);
        return Response.ok();
    }


    @Log("批量启用用户数据")
    @PutMapping(value = "/updateEnable")
    @ApiOperation(value = "批量启用用户数据", notes = "批量启用用户数据")
    public Response updateEnable(@RequestBody List<String> ids) {
        iSysUserService.updateEnable(ids);
        return Response.ok();
    }

    @Log("批量禁用用户数据")
    @PutMapping(value = "/updateDisableEnable")
    @ApiOperation(value = "禁用用户数据", notes = "禁用用户数据")
    public Response updateDisableEnable(@RequestBody List<String> ids) {
        iSysUserService.updateDisable(ids);
        return Response.ok();
    }

    @Log(value = "token查看用户")
    @ApiOperation("token查看用户")
    @GetMapping("/viewtoken")
    public Response view() {
        return Response.ok(iSysUserService.selectbytoken());
    }

    @Log(value = "查看用户")
    @ApiOperation("查看用户")
    @GetMapping("/view")
    public Response viewById(@RequestParam("Id") String Id) {
        return Response.ok(iSysUserService.getBaseMapper().selectById(Id));
    }

    @Log(value = "头像上传数据")
    @PostMapping(value = "/upload")
    @ResponseBody
    @ApiOperation(value = "头像上传数据", notes = "头像上传数据")
    public Response<SysUser> upload(@RequestParam(name = "url") String url, @RequestParam("userId") String id) {
        return Response.ok(iSysUserService.uploadObjectAttachment(url, id));
    }


}
